package com.live.proxy.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.live.proxy.R;

import java.util.Timer;
import java.util.TimerTask;

public class ToastBottomUtils {
	public static void Setinfo(Context context,String info){
		View toastView = LayoutInflater.from(context).inflate(R.layout.toast_bottom_layout, null);
		RelativeLayout layout = toastView.findViewById(R.id.toast_bottom_relative);
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
		layout.setLayoutParams(layoutParams);
		TextView text = toastView.findViewById(R.id.toast_bottom_text);
		text.setText(info);
		Toast toast = new Toast(context);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(toastView);
		toast.show();
	}
	//自定义toast 显示的时长
	public static void showCustomTimeShortToast(Context context,String msg, int time) {
		View toastView = LayoutInflater.from(context).inflate(R.layout.toast_bottom_layout, null);
		RelativeLayout layout = toastView.findViewById(R.id.toast_bottom_relative);
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
		layout.setLayoutParams(layoutParams);
		TextView text = toastView.findViewById(R.id.toast_bottom_text);
		text.setText(msg);

		Toast toast = new Toast(context);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(toastView);

		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				toast.show();
			}
		}, 0, 3500);//0秒后执行，LENGTH_LONG时间为3.5s,所以设置3500毫秒后再次执行

		new Timer().schedule(new TimerTask() {
			@Override
			public void run() {
				toast.cancel();
				timer.cancel();
			}
		}, time);//time时间后执行取消taost,取消timer.
	}
}
